﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MyBehaviorTree
{
    public class BlackBoard
    {
        private readonly Dictionary<string, BlackBoardData> datas = new Dictionary<string, BlackBoardData>();

        public void addData(string key,BlackBoardData data)
        {
            datas.Add(key, data);
        }
        private BlackBoardData getBlackBoardData(string key)
        {
            BlackBoardData data;
            if(!datas.TryGetValue(key,out data))
            {
                Debug.LogWarning("no data:" + key);   
            }
            return data;
        }

        public void updateData<T>(string key,T data)
        {
            BlackBoardData oldData = getBlackBoardData(key);
            BlackBoardData<T> type = oldData as BlackBoardData<T>;
            type.data = data;
        }
        public T getData<T>(string key)
        {
            var data = getBlackBoardData(key);
            var type = data as BlackBoardData<T>;
            return type.data;
        }
    }

    public interface BlackBoardData { }
    public class BlackBoardData<T> : BlackBoardData
    {
        public T data;
        public BlackBoardData(T data)
        {
            this.data = data;
        }
    }
}

